import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'
import Merchant from './merchant';
import shopStore from './shopstore';
import BatchWarn from './batchwarn';
import Permission from './permission';

export const constantRoutes = [{
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [{
      path: 'home',
      name: 'Home',
      component: () => import('@/views/home/index'),
      meta: {
        title: '首页',
        icon: 'home'
      }
    }]
  },

  {
    path: '/batchwarn',
    component: Layout,
    redirect: '/batchwarn/batchList',
    name: 'BatchWarn',
    meta: {
      title: '批次预警',
      icon: 'el-icon-warning-outline'
    },
    alwaysShow: true,
    children: [
      ...BatchWarn
    ]
  },
]

export const asyncRoutes = [{
    path: '/merchant',
    component: Layout,
    redirect: '/merchant/list',
    name: 'Merchant',
    meta: {
      title: '商家管理',
      icon: 'merchant',
      roles: ['super_admin']
    },
    alwaysShow: true,
    children: [
      ...Merchant
    ]
  },
  {
    path: '/shopmanage',
    component: Layout,
    redirect: '/shopmanage/shoptype',
    name: 'shopStore',
    meta: {
      title: '商品库',
      icon: 'el-icon-goods',
      roles: ['super_admin']
    },
    alwaysShow: true,
    children: [
      ...shopStore
    ]
  }, {

    path: '/permission',
    component: Layout,
    redirect: '/permission/roleList',
    name: 'Permission',
    meta: {
      title: '用户权限',
      icon: 'el-icon-user',
      roles: ['super_admin']
    },
    alwaysShow: true,
    children: [
      ...Permission
    ]
  },
  {
    path: '*',
    redirect: '/404',
    hidden: true
  }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
  console.log(router.matcher);
}

export default router
